#include "driver/gpio.h"
#include "esp_log.h"

#define TAG "button"

void listen_button_click(gpio_num_t pin, void (*callback)(void *arg)) {
  ESP_LOGI(TAG, "引脚%d监听点击事件\n", pin);
  gpio_config_t io_conf = {
      .pin_bit_mask = (1ULL << pin),
      .mode = GPIO_MODE_INPUT,
      .pull_up_en = GPIO_PULLUP_ENABLE,
      .pull_down_en = GPIO_PULLDOWN_DISABLE,
      .intr_type = GPIO_INTR_NEGEDGE // 下降沿触发
  };
  gpio_config(&io_conf);
  gpio_install_isr_service(0);
  gpio_isr_handler_add(pin, callback, NULL);
}